/*
 * ChatDialog.java
 *
 * Created on Mar 4, 2010, 5:43:53 AM
 */

package bbchess.dialogs;

import bbchess.GameManager;
import bbchess.util.ImageLoader;
import java.awt.Graphics;
import javax.swing.ImageIcon;

/**
 * NewGameDialog: This dialog pops up whenever the user chooses to start a new game,
 * or when the program first opens.
 * @author Tyler Eastman
 */
public class NewGameDialog extends ChessDialog {

    // Declare variables
    NewGamePVCDialog newGamePVCDialog;
    NewGamePVPLocalDialog newGamePVPLocalDialog;
    NewGamePVPInternetDialog newGamePVPInternetDialog;
    GameManager gameManager;

    ImageIcon pvcImage;
    ImageIcon pvpLocalImage;
    ImageIcon pvpInternetImage;

    /** Creates new form ChatDialog */
    public NewGameDialog(java.awt.Frame parent, boolean modal, GameManager gameManager) {
        super(parent, modal, true);

        newGamePVCDialog = new NewGamePVCDialog(parent, false, gameManager, this);
        newGamePVPInternetDialog = new NewGamePVPInternetDialog(parent, false, gameManager, this);
        newGamePVPLocalDialog = new NewGamePVPLocalDialog(parent, false, gameManager, this);

        this.gameManager = gameManager;

        this.setTitle("Chat");
        initComponents();

        // load images
        pvcImage = new ImageIcon(ImageLoader.getPvcImage());
        pvpLocalImage = new ImageIcon(ImageLoader.getPvpLocalImage());
        pvpInternetImage = new ImageIcon(ImageLoader.getPvpInternetImage());
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        choicePanel = new javax.swing.JPanel();
        playerVsPlayerOnlineButton = new javax.swing.JButton();
        playerVsPlayerLocalButton = new javax.swing.JButton();
        playerVsComputerButton = new javax.swing.JButton();
        gameImage = new javax.swing.JLabel();
        titlePanel = new TitlePanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Game");
        setResizable(false);

        playerVsPlayerOnlineButton.setText("Player vs Player (Online)");
        playerVsPlayerOnlineButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playerVsPlayerOnlineButtonMouseEntered(evt);
            }
        });
        playerVsPlayerOnlineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playerVsPlayerOnlineButtonActionPerformed(evt);
            }
        });

        playerVsPlayerLocalButton.setText("Player vs Player (Local)");
        playerVsPlayerLocalButton.setMaximumSize(new java.awt.Dimension(155, 23));
        playerVsPlayerLocalButton.setMinimumSize(new java.awt.Dimension(155, 23));
        playerVsPlayerLocalButton.setPreferredSize(new java.awt.Dimension(155, 23));
        playerVsPlayerLocalButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playerVsPlayerLocalButtonMouseEntered(evt);
            }
        });
        playerVsPlayerLocalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playerVsPlayerLocalButtonActionPerformed(evt);
            }
        });

        playerVsComputerButton.setText("Player vs Computer");
        playerVsComputerButton.setMaximumSize(new java.awt.Dimension(155, 23));
        playerVsComputerButton.setMinimumSize(new java.awt.Dimension(155, 23));
        playerVsComputerButton.setPreferredSize(new java.awt.Dimension(155, 23));
        playerVsComputerButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playerVsComputerButtonMouseEntered(evt);
            }
        });
        playerVsComputerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playerVsComputerButtonActionPerformed(evt);
            }
        });

        gameImage.setIcon(new ImageIcon(ImageLoader.getPvcImage()));

        javax.swing.GroupLayout choicePanelLayout = new javax.swing.GroupLayout(choicePanel);
        choicePanel.setLayout(choicePanelLayout);
        choicePanelLayout.setHorizontalGroup(
            choicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(choicePanelLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(gameImage, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(choicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(playerVsComputerButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(playerVsPlayerLocalButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(playerVsPlayerOnlineButton, javax.swing.GroupLayout.PREFERRED_SIZE, 155, Short.MAX_VALUE))
                .addContainerGap())
        );
        choicePanelLayout.setVerticalGroup(
            choicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(choicePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(choicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(gameImage, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(choicePanelLayout.createSequentialGroup()
                        .addComponent(playerVsComputerButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(playerVsPlayerLocalButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(playerVsPlayerOnlineButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        titlePanel.setBackground(new java.awt.Color(204, 204, 204));
        titlePanel.setMaximumSize(new java.awt.Dimension(281, 69));
        titlePanel.setOpaque(false);
        titlePanel.setPreferredSize(new java.awt.Dimension(267, 53));

        javax.swing.GroupLayout titlePanelLayout = new javax.swing.GroupLayout(titlePanel);
        titlePanel.setLayout(titlePanelLayout);
        titlePanelLayout.setHorizontalGroup(
            titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 271, Short.MAX_VALUE)
        );
        titlePanelLayout.setVerticalGroup(
            titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 53, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(titlePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
            .addComponent(choicePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(titlePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(choicePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void playerVsComputerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playerVsComputerButtonActionPerformed
        setVisible(false);
        newGamePVCDialog.setVisible(true);
    }//GEN-LAST:event_playerVsComputerButtonActionPerformed

    private void playerVsPlayerOnlineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playerVsPlayerOnlineButtonActionPerformed
        setVisible(false);
        newGamePVPInternetDialog.setVisible(true);
    }//GEN-LAST:event_playerVsPlayerOnlineButtonActionPerformed

    private void playerVsPlayerLocalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playerVsPlayerLocalButtonActionPerformed
        setVisible(false);
        newGamePVPLocalDialog.setVisible(true);
    }//GEN-LAST:event_playerVsPlayerLocalButtonActionPerformed

    private void playerVsComputerButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerVsComputerButtonMouseEntered
        gameImage.setIcon(pvcImage);
    }//GEN-LAST:event_playerVsComputerButtonMouseEntered

    private void playerVsPlayerLocalButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerVsPlayerLocalButtonMouseEntered
        gameImage.setIcon(pvpLocalImage);
    }//GEN-LAST:event_playerVsPlayerLocalButtonMouseEntered

    private void playerVsPlayerOnlineButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerVsPlayerOnlineButtonMouseEntered
        gameImage.setIcon(pvpInternetImage);
    }//GEN-LAST:event_playerVsPlayerOnlineButtonMouseEntered


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel choicePanel;
    private javax.swing.JLabel gameImage;
    private javax.swing.JButton playerVsComputerButton;
    private javax.swing.JButton playerVsPlayerLocalButton;
    private javax.swing.JButton playerVsPlayerOnlineButton;
    private javax.swing.JPanel titlePanel;
    // End of variables declaration//GEN-END:variables

    public class TitlePanel extends javax.swing.JPanel{
        @Override
        public void paintComponent(Graphics g) {
            g.drawImage(ImageLoader.getTitlePanelImage(), 0, 0, getWidth(), getHeight(), null);
        }
    }
}
